const {selectUser,createUser,updateCode} = require("./code.service")
const {md5Encry} = require("@/zy-common/utils")
const {send} =require("@/zy-common/utils")

class codeController{
  async saveCode(ctx,next){
    try {
      const {phone,code} = ctx.user
      const md5Code = md5Encry(String(code))
      const user = await selectUser(phone)
      if(user.length === 0){
         await createUser(phone,md5Code);
      }else{
         await updateCode(user.phone,md5Code)
      }

      send(ctx,200,'200','验证码发送成功')
      console.log("测试验证码为",code);
    } catch (error) {
      console.log(error)
    }
  }
}

module.exports = new codeController()